package com.ruoyi.project.surveys.controller;

import java.util.Date;
import java.util.List;

import com.ruoyi.common.utils.SecurityUtils;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.surveys.domain.SurveysRecords;
import com.ruoyi.project.surveys.service.ISurveysRecordsService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 填写记录Controller
 * 
 * @author zhimin-hu
 * @date 2020-05-02
 */
@RestController
@RequestMapping("/surveys/records")
public class SurveysRecordsController extends BaseController
{
    @Autowired
    private ISurveysRecordsService surveysRecordsService;

    /**
     * 查询填写记录列表
     */
    @PreAuthorize("@ss.hasPermi('surveys:records:list')")
    @GetMapping("/list")
    public TableDataInfo list(SurveysRecords surveysRecords)
    {
        startPage();
        List<SurveysRecords> list = surveysRecordsService.selectSurveysRecordsList(surveysRecords);
        return getDataTable(list);
    }

    /**
     * 导出填写记录列表
     */
    @PreAuthorize("@ss.hasPermi('surveys:records:export')")
    @Log(title = "填写记录", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(SurveysRecords surveysRecords)
    {
        List<SurveysRecords> list = surveysRecordsService.selectSurveysRecordsList(surveysRecords);
        ExcelUtil<SurveysRecords> util = new ExcelUtil<SurveysRecords>(SurveysRecords.class);
        return util.exportExcel(list, "records");
    }

    /**
     * 获取填写记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('surveys:records:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(surveysRecordsService.selectSurveysRecordsById(id));
    }

    /**
     * 新增填写记录
     */
    @PreAuthorize("@ss.hasPermi('surveys:records:add')")
    @Log(title = "填写记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SurveysRecords surveysRecords)
    {
        surveysRecords.setCreateBy(SecurityUtils.getUsername());
        return toAjax(surveysRecordsService.insertSurveysRecords(surveysRecords));
    }

    /**
     * 修改填写记录
     */
    @PreAuthorize("@ss.hasPermi('surveys:records:edit')")
    @Log(title = "填写记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SurveysRecords surveysRecords)
    {
        surveysRecords.setUpdateBy(SecurityUtils.getUsername());
        return toAjax(surveysRecordsService.updateSurveysRecords(surveysRecords));
    }

    /**
     * 删除填写记录
     */
    @PreAuthorize("@ss.hasPermi('surveys:records:remove')")
    @Log(title = "填写记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(surveysRecordsService.deleteSurveysRecordsByIds(ids));
    }
}
